package com.pyue.eam.regi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pyue.eam.admin.api.entity.regi.PartLibEntity;
import com.pyue.eam.regi.mapper.PartLibMapper;
import com.pyue.eam.regi.service.PartLibService;
import lombok.AllArgsConstructor;
import org.javers.core.diff.Change;
import org.javers.core.diff.changetype.ValueChange;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 零件库
 *
 * @author lucc
 * @date 2023-10-12 20:38:39
 */
@Service
@AllArgsConstructor
public class PartLibServiceImpl extends ServiceImpl<PartLibMapper, PartLibEntity> implements PartLibService {
    private final ApplicationEventPublisher applicationEventPublisher;

    @Override
    public Boolean updatePartLib(PartLibEntity partLibEntity) {
        // 版本记录
        // AsyncUtil.execute(() -> DataAuditor.compare(partLibEntity, baseMapper.selectById(partLibEntity.getId())).forEach(this::printChange));

        return updateById(partLibEntity);
    }


    private void printChange(Change change) {
        ValueChange vc = (ValueChange) change;
        System.err.printf("%s不匹配，新值 %s 旧值 %s%n", vc.getPropertyName(), vc.getLeft(), vc.getRight());
    }

}
